#include <stdio.h>
#include <stdbool.h>
#include <string.h>

#define Map_Size 20
#define ElementType int

struct Stack
{
    ElementType arr[Map_Size];
    int len;
};
typedef struct Stack stack;

void InitStack(stack *s)
{
    memset(s->arr, 0, Map_Size);
    s->len = 0;
}

void Push(stack *s, ElementType value)
{
    if (s->len == Map_Size)
    {
        printf("Push stack error\n");
    }
    s->arr[s->len++] = value;
}

ElementType* Pop(stack *s)
{
    if (s->len == 0)
    {
        printf("Pop stack error\n");
        return NULL;
    }
    return &s->arr[--s->len];
}

bool IsStackEmpty(stack *s)
{
    return s->len == 0;
}

int main()
{
    stack s;
    InitStack(&s);
    // for (int i = 0; i < 10; i++)
    // {
    //     Push(&s, i+1);
    // }

    // while (IsStackEmpty(&s) == false)
    // {
    //     printf("%d ", *Pop(&s));
    // }
    // printf("\n");

    int num = 0;
    int systemNum = 0;
    scanf("%d %d", &num, &systemNum);
    while (num != 0)
    {
        int temp = num % systemNum;
        Push(&s, temp);
        num /= systemNum;
    }
    while (IsStackEmpty(&s) == false)
    {
        int *res = Pop(&s);
        if (*res < 10)
        {
            printf("%d", *res);
        }
        else
        {
            printf("%c", *res + 87);
        }
        
    }
    printf("\n");
    
    return 0;
}
